﻿/**
 *	\file		dream.cxx
 *	\date		(2014-12-30 17:31:00)/(2014-12-30 17:31:00)
 *-----------------------------------------------------------------------------
 *	\brief
 *	\version	1.0.0.1
 *	\author		Nick Shallery	(nicknide@gmail.com)
 *	\copyright	YOU HAVE ALL LEFT WITH THIS CODE WHILE YOU KEEP COMMENT IN EVERY COPY.
 *-----------------------------------------------------------------------------
**/

#include	"./dream.h"
#include	"./recurrence.hxx"
#include	"./reg_path.hxx"

namespace lxsamsara{namespace _inst{class dream_inst;}}
class lxsamsara::_inst::dream_inst
	: public lolix::itf_Tbase<dream_inst, dream>
{
	LOLIX_DEFINE_ITF(lxsamsara::_inst::dream_inst, lxsamsara::dream, (0xacdbf507, 0x1ef94746, 0x9381d524, 0xd5a27847));
	_RegBack _reg_back;
	lolix::dynamic_allocator* _alc;
	~dream_inst();
public:
	static LOLIX_RETNV create_inst(this_type** out_ptr, lolix::dynamic_allocator* alc, lolix::ref_factory* ref_fac, _RegBack const* regBack);
	LOLIX_INTERFACE_DEF(awaken, void, (void)const);
	LOLIX_INTERFACE_DEF(broken, void, (void)const);
};


lxsamsara::_inst::dream_inst::~dream_inst(void)
{
	_alc->release();
}


lolix::LOLIX_RETNV
lxsamsara::_inst::dream_inst::create_inst(this_type** out_ptr, lolix::dynamic_allocator* alc, lolix::ref_factory* ref_fac, _RegBack const* regBack)
{
	this_type* ptr;
	LOLIX_RETNV rtv;
	if ( LOLIX_CHECK_ERROR(rtv = __Create_inst_set_alc(&ptr, alc, ref_fac)) )
		return rtv;
	ptr->_reg_back = *regBack;
	*out_ptr = ptr;
	return rtv;
}


void
lxsamsara::_inst::dream_inst::awaken(void)const
{
	pop_reg(&this->_reg_back, (void*)lolix::LOLIX_INFO_REOPERATOR);
}


void
lxsamsara::_inst::dream_inst::broken(void)const
{
	_RegBack regBack(this->_reg_back);
	this->release();
	pop_reg(&regBack, (void*)lolix::LOLIX_INFO_REOPERATOR);
}


extern "C" lolix::LOLIX_RETNV
CreateDreamInst(lxsamsara::dream** out_ptr, lxsamsara::_inst::recurrence_inst* rinst, _RegBack const* regBack)
{
	auto alc = rinst->__get_alc();
	auto ref_fac = rinst->__get_ref_fac();
	return lxsamsara::_inst::dream_inst::create_inst((lxsamsara::_inst::dream_inst**)out_ptr, alc, ref_fac, regBack);
}
